/**
 * Created by BobyCo on 2017/11/22 0022.
 */
$(function () {
    var $navbar = $(".weui-navbar"), st,
        navbarWidth = $navbar.width(), // 分类导航条的宽度
        $back = $('#back'), // 返回按钮
        $deleteAll = $("#searchClear"); // 删除选中
    $navbar.attr('otop', $navbar.offset().top);

    $(".product-page").scroll(function () {
        st = Math.max(this.scrollTop || document.documentElement.scrollTop);
        if (st > parseInt($navbar.attr('otop'))) {
            $navbar.css({ 'position': 'fixed', top: 0, "width": navbarWidth });
        } else {
            $navbar.css({ 'position': 'absolute' });
        }
    });

    // 取消按钮
    $back.click(function () {
        window.location.href = getRealPath() + "/supplier/products.html";
    });

    // 删除当前页签选中
    $deleteAll.click(function () {
        var rows = $('.weui-tab__bd-item--active').find('.weui-check:checked+.weui-icon-checked').parentsUntil(".confirm-checkbox").filter('label');
        if (rows.length == 0) {
            $.toptip('您还没有选择产品哦~', 'warning');
            return;
        }
        rows.remove();
        window.location.href = getRealPath() + "/supplier/products.html";
    });

    // 导航条页签滑动初始化
    $(".swiper-container").swiper({
        slidesPerView: 4,
        slidesPerGroup: 4,
        spaceBetween: 10
    });
    // 页签切换
    $(".swiper-slide").off("click").click(function (e) {
        $(".swiper-slide").removeClass("swiper-slide--on");
        $(this).addClass("swiper-slide--on");
        $(".weui-navbar__item").eq($(this).index()).trigger("click");
    });
});